package com.geticsen.leetcode;
//https://leetcode-cn.com/problems/invert-binary-tree/
public class Solution_226 {
    TreeNode temp;

    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        invert(root);
        return root;
    }

    public void invert(TreeNode node) {
        if (node == null) {
            return;
        }
        if (node.left != null) {
            invert(node.left);
        }
        if (node.right != null) {
            invert(node.right);
        }
        //翻转
        temp = node.left;
        node.left = node.right;
        node.right = temp;
    }
}
